using System;
using System.Collections.Generic;

using IBatisNet.DataMapper;

using log4net;

using GymManager.Exception;
using GymManager.Persistence.VO;

namespace GymManager.Persistence.DAO
{
    /// <summary>
    /// Class responsible by getting information from database about roles
    /// </summary>
    public class RoleDAO
    {
        // logger instance
        private ILog _logManager = LogManager.GetLogger(typeof(RoleDAO));

        /// <summary>
        /// Method responsible by getting all roles
        /// </summary>
        /// <returns>List of all avaliable roles</returns>
        public IList<Role> findAll()
        {
            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("Begin Method");
            }

            // list of roles to be returned
            IList<Role> roleList = null;

            try
            {
                ISqlMapper ibatisMapper = DAOManager.getInstance();
                roleList = ibatisMapper.QueryForList<Role>("Role.findAll", null);
            }
            catch (System.Exception ex)
            {
                _logManager.Error("Error while retrieving role information", ex);
                throw new PersistenceException("Error while retrieving role information", ex);
            }

            if (_logManager.IsInfoEnabled)
            {
                _logManager.Info("End Method");
            }

            return roleList;
        }
    }
}
